package gaml.yaml;

import gaml.yaml.ahchor.YamlAnchor;

import java.util.ArrayList;
import java.util.HashMap;


/**
 * a quant of yaml structure, loaded into system
 * @author shnireck_vi
 *
 */
public abstract class YamlNode {
	YamlNode parent = null;
	int level = 0;
	String tag = "";
	YamlAnchor anchor = null;
	String comment = "";
	
	/**
	 * @return get parent node for this node 
	 * null if this node is root node
	 */
	public YamlNode getParent () { return parent; }
	
	/**
	 * @return node tree level (for identation and so on...)
	 */
	public int getLevel () { return level; }
	
	/**
	 * @return tagged type for node
	 */
	public String getTag () { return tag; }
	
	/**
	 * set node type in node tag
	 * @param string value for type
	 * @return value host object
	 */
	public YamlNode setTag (String tag) { this.tag = tag; return this; }
	
	/**
	 * @return get unique yaml anchor to this node
	 */
	public YamlAnchor getAnchor () { return anchor; }
	
	/**
	 * specifies anchor for node
	 * @return host object
	 */
	public YamlNode setAnchor (YamlAnchor anchor) {
		this.anchor = ((null == anchor) ? null : anchor.setNode (this));
		return this;
	}
	
	/**
	 * @return string value of a scalar node
	 */
	public abstract String getValue ();
	
	/**
	 * @param value scalar node string value
	 * @return sets value if this node is scalar
	 */
	public abstract YamlNode setValue (String value);
	
	/**
	 * @return yaml node comment (if any), without leeding #
	 */
	public String getComment () { return comment; }
	
	/** define comment text for node
	 * @param comment text of comment
	 * @return host object
	 */
	public YamlNode setComment (String comment) { this.comment = comment; return this; }
	
	/**
	 * @return hash of subnodes of map node  
	 */
	public abstract HashMap <YamlNode, YamlNode> getMappingChildren ();
	
	/**
	 * get child node of map-type node by mapping key value
	 * @param key mapping key
	 * @return child node object
	 */
	public abstract YamlNode getChild (YamlNode key);
	
	/**
	 * @return vector of subnodes of list node
	 */
	public abstract ArrayList <YamlNode> getSequenceChildren ();
	
	/**
	 * get child node for list-type node by child
	 * node index
	 * @param index child node index
	 * @return child node object
	 */
	public abstract YamlNode getChild (int index);
	
	/**
	 * adds new child to map node
	 * @param key map node child key
	 * @param val map node child value
	 * @return host object
	 */
	public abstract YamlNode addChild (YamlNode key, YamlNode val);
	
	/**
	 * adds child to list node
	 * @param value child node value
	 * @return host object
	 */
	public abstract YamlNode addChild (YamlNode value);
	
	/**
	 * check if there any data in node
	 * @return 
	 */
	public abstract boolean isEmpty ();
}
